///**
// * projectName: 47movie-project
// * fileName: MyGlobaleFilter.java
// * packageName: com.woniu.gateway.config
// * date: 2021-01-04 3:20 下午
// * copyright(c)
// */
//package com.damie.gateway.config;
//
//
//import com.damie.common.jwtuilts.Code;
//import com.damie.common.jwtuilts.JwtUtil;
//import com.damie.gateway.controller.GatewaySetting;
//import com.damie.gateway.handler.NoTokenException;
//import com.damie.gateway.handler.TokenIsNotException;
//import io.jsonwebtoken.ClaimJwtException;
//import lombok.SneakyThrows;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.cloud.gateway.filter.GatewayFilterChain;
//import org.springframework.cloud.gateway.filter.GlobalFilter;
//import org.springframework.core.Ordered;
//import org.springframework.stereotype.Component;
//import org.springframework.web.server.ServerWebExchange;
//import reactor.core.publisher.Mono;
//
//import javax.annotation.Resource;
//import java.util.LinkedList;
//import java.util.List;
//
///**
// * @version: V1.0
// * @author: light
// * @className: MyGlobaleFilter
// * @packageName: com.woniu.gateway.config
// * @description:
// * @data: 2021-01-04 3:20 下午
// **/
//@Component
//public class MyGlobaleFilter implements GlobalFilter, Ordered {
//    @Resource
//    private GatewaySetting gatewaySetting;
//
//    @SneakyThrows
//    @Override
//    public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
//        System.out.println("========全局拦截器===========");
//
//        String ip = exchange.getRequest().getRemoteAddress().getAddress().getHostAddress();
//
//
//        //哪些请求可以通过
//        List<String> fil = gatewaySetting.getWhiteUrls();
//
//
//        String url = exchange.getRequest().getURI().toString();
//        for (int i=0;i<fil.size();i++){
//            String s = fil.get(i);
//            if (url.contains(s)){
//                System.out.println("我走了");
//                return chain.filter(exchange);
//            }
//            System.out.println("我没走掉走了");
//            continue;
//        }
//        //没有放行的解token
//        List<String> token = exchange.getRequest().getHeaders().get(Code.token.toString());
//        System.out.println(token);
//        if (token==null||token.size()<=0||token.get(0)==null){
//            throw new NoTokenException(",token了?");
//        }
//        try {
//            JwtUtil.parseToken(token.get(0));
//        }catch (ClaimJwtException e){
//            throw new TokenIsNotException(",token不对劲啊"+e.getLocalizedMessage());
//        }
//        return chain.filter(exchange);
//    }
//
//    @Override
//    public int getOrder() {
//        return 1;
//    }
//}
